#pragma once

#include <vld.h>

#include "BeanieIncludes.h"
#include "BeanieDefines.h"
#include "BeanieEnums.h"

#include "BeanieTexture.h"

#include "WindowFramework.h"
#include "Direct3DFramework.h"
#include "DirectInputFramework.h"
#include "FpsFramework.h"
#include "TimeFramework.h"
#include "FmodFramework.h"

class BeanieCore
{
private:
	bool m_exit;
	int m_exitMessage;

	WindowFramework m_window;
	Direct3DFramework m_graphics;
	DirectInputFramework m_input;

	FpsFramework m_fps;
	TimeFramework m_time;
public:
	FmodFramework m_sound;
	

	BeanieCore();
	~BeanieCore();

	//------------------//
	//--CORE FUNCTIONS--//
	//------------------//

	void init(
		char* a_windowName,
		int a_windowColor,
		int a_windoWidth,
		int a_windowHeight,
		bool a_windowed,
		Handle* a_windowHandle);
	void release();
	void update();

	bool error();
	bool exit(){return m_exit;}
	int exitMessage(){return m_exitMessage;}
	int getWindowWidth(){return m_window.m_windowWidth;}
	int getWindowHeight(){return m_window.m_windowHeight;}
	int getScreenWidth(){return m_window.m_screenWidth;}
	int getScreenHeight(){return m_window.m_screenHeight;}

	int getFPS(){return m_fps.getFPS();}
	float getTime(){return m_time.getTime();}
	float getElapsed(){return m_time.getElapsed();}

	void getCam(V2DF* a_min, V2DF* a_max)
	{
		*a_min=m_graphics.m_camMin;
		*a_max=m_graphics.m_camMax;
	}

	int* ptrFPS(){return m_fps.ptrFPS();}
	float* ptrTime(){return m_time.ptrTime();}
	float* ptrElapsed(){return m_time.ptrElapsed();}

	//-------------------//
	//--INPUT FUNCTIONS--//
	//-------------------//

	void acquire();
	bool keyInput(int a_key);
	bool keyPress(int a_key);
	bool anyKey();
	bool mouseInput(int a_button);
	bool mousePress(int a_button);
	void mouseDelta(
		long* a_x,
		long* a_y,
		long* a_z);
	void mousePosition(
		int* a_x,
		int* a_y);

	//----------------------//
	//--GRAPHICS FUNCTIONS--//
	//----------------------//

	void createTexture(BeanieTexture* a_texture, char* a_filePath);

	void updateCamera(V2DF a_camPos);
	void updateTransform(BeanieTexture* a_texture,
		V2DF a_transform, V2DF a_scale, float a_rotate,
		V2DF* a_pos = 0, V2DF* a_min = 0, V2DF* a_max = 0);

	void drawBegin();
	void drawEnd();
	void drawLine(V2DF a_start, V2DF a_end, int a_color);
	void drawText(char* a_text, V2DF a_pos, int a_color);
	void drawTexture(BeanieTexture* a_texture);
};